package com.example.samplecam;

import android.graphics.Bitmap;
import android.graphics.Color;

public class ImageProcessor {

	static public Bitmap ExtractSkinColor(Bitmap sourceImage) {
		int width = sourceImage.getWidth();
		int height = sourceImage.getHeight();
		Bitmap bmpSkin = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
		int color = 0;
		float[] hsv = {0f, 0f, 0f};
		for(int x=0; x<width; x++){
			for(int y=0; y<height; y++){
				color = sourceImage.getPixel(x, y);				
				Color.colorToHSV(color, hsv);
				if ((hsv[0]<60 && hsv[1]>0.5 && hsv[2]>0.5)){ // not red to yellow color
					bmpSkin.setPixel(x, y, Color.rgb(255,255,255));// original color Color.HSVToColor(hsv));
				}
				else
				{
					bmpSkin.setPixel(x, y, Color.rgb(0, 0, 0));
				}
			}
		}
		return bmpSkin;
	}
}
